/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aliasMatching.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author amendrashrestha
 */
public class TestTableModel extends AbstractTableModel {

    private String[] columnNames = {"User 1", "User2", "Stylo", "Time", "Fusion"};
    private Vector data = new Vector();
    public final Object[] longValues = {"", "", new Float(20), new Float(20), new Float(20)};
    List<List> all_rows;
    
    public TestTableModel() {
        all_rows = new ArrayList();
    }

    public void SetValue(List value) {
        this.all_rows = value;
        getValuefromList(all_rows);
        this.fireTableDataChanged();
    }

    public void getValuefromList(List<List> rows) {
        for (int i = 0; i < all_rows.size(); i++) {
            Object[] tempValues = all_rows.get(i).toArray(new Object[0]);
            insertData(tempValues);
        }
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public Object getValueAt(int row, int col) {
        return ((Vector) data.get(row)).get(col);
    }

    public String getColumnName(int col) {
        return columnNames[col];
    }

    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }

    public void setValueAt(Object value, int row, int col) {
        ((Vector) data.get(row)).setElementAt(value, col);
        fireTableCellUpdated(row, col);
    }

    public boolean isCellEditable(int row, int col) {
        if (4 == col) {
            return true;
        } else {
            return false;
        }
    }

    public void insertData(Object[] values) {
        data.add(new Vector());
        for (int i = 0; i < values.length; i++) {
            ((Vector) data.get(data.size() - 1)).add(values[i]);
        }
        fireTableDataChanged();
    }

    public void removeRow(int row) {
        data.removeElementAt(row);
        fireTableDataChanged();
    }
}
